Skip to main content

Extension SDK

With the Extension SDK, you can implement your own functions in C and call them from the IEC application.

For this connection, the C code is integrated into the runtime system in the form of a separate dynamic component (shared object).

There are two ways to include:

  • Prepared on the controller: The dynamic component is already configured to the CODESYS runtime system (a shared object exists and is configured on the Linux system). Then, only the respective IEC library is required.

  • In the form of an IEC library with an integrated dynamic component. Nothing needs to be prepared on the Linux system itself. When using the IEC library, the dynamic component is automatically added to the CODESYS runtime system and used.

In both cases, the user has to be able to create a shared object which is suitable for the architecture of the runtime system (x64/ARM6/ARM7/AARCH64). The Extension SDK supports you in creating this kind of dynamic component (shared object).

The following describes how to create the library and the dynamic component for both variants.

Development Environment

. Development Environment
  • Open CODESYS and create a new library.

  • Set the title of the library(Project Information, Summary tab) and save the library under the same name.

  • Add the desired functions and mark them as External implementation.

    • In the context menu of the function in the project navigator, click Properties. On the Build tab, select External implementation.

    • Note: The function has to contain "_cext" in the name.

  • Now generate the *c and *m4 files:

    • Click Build → Generate Runtime System Files.

    • Select M4 interface file and C stub file.

    • Select the save location.

Linux

  1. Copy the Extension SDK to a Linux system which has the corresponding compile environment for the target system.

    By default, you find the Extension SDK under:

    C:\Program Files\CODESYS <version>\CODESYS\CODESYS Control SL Extension Package\<version>\ExtensionSDK. The directory will be referred to as <SDK DIR> in the following steps..

  2. Create a new folder where you create the C implementation. This folder is in the following <PROJECT DIR>.

  3. Navigate to <PROJECT DIR> and run: $ make -f <SDKDIR>/makefile newproject

  4. Copy the *c and *m4 files you created in the Development Environment to <PROJECT DIR>.

  5. Implement the functions in C.

  6. Create the shared object: $ make all

    The shared object is generated and located in <PROJECT DIR>/out/libCmpMyTest.so.

As a result, you have created a dynamic component which can now be called from the IEC application via your IEC library. Details about the build process (make) can also be found in the makefiles and README file in the Extension SDK.

Now decide on one of the two following ways to include the component:

Including the dynamic component

You have the following options to include the component:

Including the dynamic component on the target device

This method allows you to include the shared object previously created in C into the runtime system. No additional system permissions are required for the user and the library can be rolled out to the devices using familiar methods.

  1. Copy the shared object created above to the runtime system.

  2. Copy the shared object to /usr/lib/ or an equivalent library directory where libraries are found by the system.

  3. Stop the runtime system (example: $ sudo /etc/init.d/codesyscontrol stop)

  4. Open /etc/CODESYSControl_User.cfg with administrator permissions: $ sudo nano /etc/CODESYSControl_User.cfg

  5. In the [ComponentManager] section, add the created shared objects:

    [ComponentManager]
    Component.1=CmpFirstTest
    Component.2=CmpSomeOtherComponent
    ...

    Note: The number is a incremental number which must not conflict with existing components.

  6. Start the runtime system: $ sudo /etc/init.d/codesyscontrol start

    Now you can check whether the component has been loaded: $ cat /tmp/codesyscontrol.log

Including the dynamic component in the IEC library

Add the dynamic component to the IEC library using the "C Code Integration" functionality. For more information, see C Code Integration in the general help.

  1. Open the IEC library.

  2. In POUs, add a C-Implemented Library object.

  3. In this object, add an Object file for devices:

    • Select the previously built dynamic component (file) and add it.

    • Specify a suitable component name.

    • Select the suitable device.

    Now, when using this library with the selected device, the dynamic component is automatically added to the runtime system and can be called using the POUs of the library.

Other

Restrictions:

  • With the Extension SDK, only C code can be included.

  • A debugger cannot be use to examine or debug the C code (for example, as in the programming system).

  • The C code cannot "interact" with the runtime system or the IEC application. This means:

    • Automatic access to variables of the IEC application is not possible.

    • Access to functionality of the runtime system is not possible. However, access to variables of the IEC application are of course possible by passing them to a function implemented in C code by reference (for example, via POINTER).

Usage of the interface only as a member of the Linux codesysuser user group

No

Process separation

No